(function() {
'use strict';

angular
	.module('votingBackend')
	.controller('MainController', MainController);

/** @ngInject */
function MainController($timeout, webDevTec, toastr, $scope, $http, userDataService) {

//initialize variables for show/hide of jumbotron and list generators
	$scope.jumbotronNotVisible = false;
	$scope.quizListNotVisible = true;
	$scope.voteListNotVisible = true;

	$scope.showQuizGenerator = function() {
		$scope.jumbotronNotVisible = true;
		$scope.voteListNoteVisible = true;
		$timeout(function(){ $scope.quizListNotVisible = false }, 1000  )
	}

	$scope.showVoteGenerator = function() {
		$scope.jumbotronNotVisible = true;
		$scope.quizListNotVisible = true;
		$timeout(function(){
		$scope.voteListNotVisible = false}, 1000
		);
	}

	userDataService.provideAllUserData(1).then(function () {
		$scope.userData = userDataService.userData;
		$scope.userName = $scope.userData.name;
		$scope.userQuizzes = $scope.userData.quizzes; 
	})

	//$timeout(function(){console.log($scope.userData)},500);

	$scope.createNewQuiz = function() {
  
	var newQuiz = {
		name: $scope.quizName,
		length: $scope.quizLength
	}

	$http.post('http://localhost:1337/quiz/create', newQuiz)
		.success(function (data, status, headers) {
			alert('new quiz created');
		}).error(function (data, status, headers) {
			alert('error creating new quiz')
			console.log(data, status, headers)
		})
	}
}
})();
